/*
 * @Author: CodeHare
 * @Date: 2023-10-13 13:40:19
 * @LastEditors: CodeHare
 * @LastEditTime: 2023-10-20 16:01:10
 * @Description: 用户信息页面
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';
import 'package:yt_devops/components/app_bar/app_bar_widget.dart';
import 'package:yt_devops/components/app_permission/permission_widget.dart';
import 'package:yt_devops/components/gaps.dart';
import 'package:yt_devops/pages/mine/user_manage/user_manager_user_detail/user_avatar_widget.dart';
import 'package:yt_devops/resources/resources.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';
import 'package:yt_devops/utils/constants/permission_page_constant.dart';
import '../../../components/brn/brn_bottom_button_panel.dart';
import '../../site/site_setting/site_setting_base_info/widgets/item_widget.dart';
import 'user_info_controller.dart';

class UserInfoPage extends GetView<UserInfoController> {
  UserInfoPage({Key? key}) : super(key: key);
  @override
  final controller = Get.put(UserInfoController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder<UserInfoController>(
      builder: (_) {
        return Scaffold(
          backgroundColor: Colour.backgroundColor,
          appBar: AppBarWidget.withRightActions(
            ResKey.mineUserManagerUserDetail.tr,
            actions: [
              Visibility(
                visible: !controller.isEnableEdit,
                child: PermissionWidget(
                  permissionStringList: const [PermissionConstant.mineIndividualEdit],
                  child: IconButton(
                    icon: Image.asset(ImageAssets.siteSettingBaseInfoEdit),
                    onPressed: controller.edit,
                  ),
                ),
              )
            ],
          ),
          body: Column(
            children: [
              Gaps.vGap10,
              Container(
                color: Colour.white,
                child: UserAvatarWidget(controller.avatar, (avatar) {
                  controller.avatar = avatar;
                  controller.update();
                }, isCanClick: controller.isEnableEdit, isShowRightArrow: controller.isEnableEdit),
              ),
              Gaps.vGap10,
              ItemWidget(
                ResKey.mineUserManagerUserName.tr,
                controller.userNameController,
                titleColor: Colour.mainTextColor,
                titleFont: 16,
                isCanEdit: controller.isEnableEdit,
                isRequired: controller.isEnableEdit,
                textChangeCallBack: (text) {
                  controller.update();
                },
              ),
              ItemWidget(
                ResKey.mineUserManagerMobile.tr,
                controller.mobileController,
                titleColor: Colour.mainTextColor,
                titleFont: 16,
                isCanEdit: controller.isEnableEdit,
                isRequired: false,
                textChangeCallBack: (text) {},
              ),
              ItemWidget(ResKey.mineUserManagerUserEmail.tr, controller.emailController,
                  titleColor: Colour.mainTextColor,
                  titleFont: 16,
                  isShowDivider: false,
                  isCanEdit: controller.isEnableEdit),
            ],
          ),
          bottomNavigationBar: controller.isEnableEdit
              ? Container(
                  color: Colors.white,
                  height: 82 + ScreenUtil().bottomBarHeight,
                  padding: EdgeInsets.only(bottom: ScreenUtil().bottomBarHeight),
                  child: YtBrnBottomButtonPanel(
                      enableMainButton: controller.userNameController.text.isNotEmpty,
                      mainButtonName: ResKey.save.tr,
                      mainButtonOnTap: () => controller.save(),
                      secondaryButtonName: ResKey.cancel.tr,
                      enableSecondaryButton: true,
                      secondaryButtonBorder: Border.all(color: Colour.dividerColor),
                      secondaryButtonOnTap: () => controller.cancel()),
                )
              : null,
        );
      },
    );
  }
}
